<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class WarehouseLocation extends BaseModel
{
    use HasFactory;
    protected $table = 'warehouse_location';
    // 允许批量操作的字段
    protected $fillable = ['warehouse_location','warehouse_id','goods_shelf_id','is_del','created_at','updated_at'];

    public function scopeSearch($query,$params)
    {
        if(!empty($params['warehouse_location'])){
            $query->where('warehouse_location',$params['warehouse_location']);
        }
        if(!empty($params['warehouse_id'])){
            $query->where('warehouse_id',$params['warehouse_id']);
        }
        if(!empty($params['goods_shelf_id'])){
            $query->where('goods_shelf_id',$params['goods_shelf_id']);
        }
        $query->where('is_del',2);
        return $query;
    }

    public function goods_shelf(){
        return $this->hasOne(GoodsShelf::class,'id','goods_shelf_id');
    }
}
